function login(){
    var userName = $("#userName").val();
    var password = $("#password").val();
    var md5Pwd = md5(password);
    var params = {
        "userName":userName,
        "password":md5Pwd
    };
    httpPost("/toLogin/checkUser",params);
   /* window.location.href = '/toLogin/checkUser?userName='+userName+"&password="+md5Pwd;*/
}


function register(){
    var flag = validatePwd();
    if(flag){
        var userName = $("#name").val();
        var password = $("#pwd").val();
        var md5Pwd = md5(password);
        var params = {
            "userName":userName,
            "password":md5Pwd
        };
        httpPost("/UserController/registerUser",params);
    }
}

function validatePwd(){
    var pwdNew = $("#pwd").val();
    var pwdOld = $("#pwd2").val();
    if(pwdNew == pwdOld){
        return true;
    }else{
        $("#message").html("两次密码不相同");
        $("#message").css("color","red");
        return false;
    }
}


/**
 * 拼接字符表单 并提交
 * @param url
 * @param params
 * @returns {HTMLFormElement}
 */
function httpPost(url,params){
    var temp = document.createElement("form");
    temp.action = url;
    temp.method = "post";
    temp.style.display = "none";

    for(var p in params){
        var opt = document.createElement("textarea");
        opt.name = p;
        opt.value = params[p];
        temp.appendChild(opt);
    }
    document.body.appendChild(temp);
    temp.submit();
    return temp;
}
